package com.asiainfo.iam.controller;


import com.asiainfo.iam.entity.vo.MessageBase;
import com.asiainfo.iam.service.MessageServiceTest;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/iam/message_test")
@Api(tags = "模拟mqAPI")
public class MQTest {

    @Autowired
    private MessageServiceTest messageServiceTest;

    @PostMapping("/process")
    public ResponseEntity<String> processMessage(
            @Valid @RequestBody MessageBase message,
            @RequestParam(defaultValue = "FULL") String syncType) {

        try {
            if ("FULL".equalsIgnoreCase(syncType)) {
                messageServiceTest.handleFullData(message.getMsgObject(), message);
            } else {
                messageServiceTest.handleIncrementalData(
                        message.getMsgObject(),
                        message.getMsgOperateType(),
                        message
                );
            }
            return ResponseEntity.ok("消息处理成功！");
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("消息处理失败: " + e.getMessage());
        }
    }
}
